package org.smth.search.query.impl;

import com.google.inject.Singleton;
import com.google.inject.Inject;

import org.smth.search.config.IndexerConfig;
import org.smth.search.indexer.IndexAnalyzer;
import org.smth.search.indexer.impl.EnumAllTokenStream;
import org.smth.search.query.QueryAnalyzer;
import org.apache.lucene.analysis.TokenStream;

import java.io.Reader;

@Singleton
public class QueryAnalyzerImpl extends QueryAnalyzer {

	@Inject
	private IndexerConfig config;

	@Inject
	private IndexAnalyzer analyzer;

	public TokenStream tokenStream(String fieldName, Reader reader) {
		TokenStream stream = analyzer.tokenStream(fieldName, reader);
		if (stream instanceof EnumAllTokenStream) {
			EnumAllTokenStream s = (EnumAllTokenStream) stream;
			s.setMinch(config.getMaxCHWordLen());
			s.setMinen(config.getMaxENWordLen());
		}
		return stream;
	}

}
